// Taken from: http://www.webmasterworld.com/javascript/3660908.htm
function getURLParam(strParamName){
	var strReturn = "";
	var strHref = window.location.href;
	if ( strHref.indexOf("?") > -1 ){
		var strQueryString = strHref.substr(strHref.indexOf("?"));
		var aQueryString = strQueryString.split("&");
		for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
			if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
				var aParam = aQueryString[iParam].split("=");
				strReturn = aParam[1];
				break;
			}
		}
	}
	return strReturn;
}

// This will redirect if we have a provider ID
function crossSiteRedirect(){
	var strHref = window.location.href;
	if ( strHref.indexOf("FWM") > -1 ){
		if ( strHref.indexOf("Search.aspx?providerID") > -1 ){
			window.location.href='https://fisonline.tribalhosted.co.uk/TowerHamlets/EarlyYears/PublicEnquiry/Search.aspx?providerID='+getURLParam('providerID');
		}
		else {
			window.location.href='https://fisonline.tribalhosted.co.uk/TowerHamlets/EarlyYears/PublicEnquiry'
		}
	}
	if ( strHref.indexOf("PublicEnquiry") > -1 ){
		if ( strHref.indexOf("Search.aspx?providerID") > -1 ){
			window.location.href='https://fisonline.tribalhosted.co.uk/TowerHamlets/EarlyYears/FWM/Search.aspx?providerID='+getURLParam('providerID');
		}
		else {
			window.location.href='https://fisonline.tribalhosted.co.uk/TowerHamlets/EarlyYears/FWM'
		}
	}
}
